//可否下拉
var is_bool=true;
// 页码信息
var page_no=1;

//获取每月一测定时任务
var month_question_inter_val={};

$(function() {
    getEvaluationList();

    $(window).scroll(function(){
    　　var scrollTop = $(this).scrollTop();
    　　var scrollHeight = $(document).height();
    　　var windowHeight = $(this).height();
    　　if(scrollTop + windowHeight == scrollHeight&&is_bool){
    　　　　getEvaluationList();
    　　}
    });

    var SubMit1 = document.querySelector('.SubMit1');
    var modle1 = document.querySelector('.Model1');
    SubMit1.index = true;
    SubMit1.addEventListener('click', function() {
        if (SubMit1.index) {
            modle1.className = 'Model Model1 Model-active'
            SubMit1.index = !SubMit1.index
        } else {
            return false
        }
    })
    modle1.addEventListener('click', function() {
        if (!SubMit1.index) {
            modle1.className = 'Model Model1'
            SubMit1.index = !SubMit1.index
            // window.location.reload();
        } else {
            return false
        }
    })

    var SubMit2 = document.querySelector('.SubMit2');
    var modle2 = document.querySelector('.Model2');
    SubMit2.index = true;
    SubMit2.addEventListener('click', function() {
        if (SubMit2.index) {
            modle2.className = 'Model Model2 Model-active'
            SubMit2.index = !SubMit2.index
        } else {
            return false
        }
    })
    modle2.addEventListener('click', function() {
        if (!SubMit2.index) {
            modle2.className = 'Model Model2'
            SubMit2.index = !SubMit2.index
            // window.location.reload();
        } else {
            return false
        }
    })


    $('.Model1 .use-integral').click(function(e){
        e.stopPropagation();
        location.href=getRootPath()+'/GasHome/Goods/Index?park_id='+$('#park_id').val();
    });
    // 每月一侧监控
    getMonthQuestion();
    monthQuestionInterVal();
})

function monthQuestionInterVal(){
    month_question_inter_val=setInterval(function(){
        getMonthQuestion();
    },30000);
}

function getEvaluationList() {
    //禁止滚动
    is_bool=false;
    $('.load').show();
    $.ajax({
        type: "post",
        url: "Api/Evaluation/getEvaluationList",
        data: {
            park_id: $('#park_id').val(),
            page_no:page_no
        },
        async: true,
        dataType: 'json',
        success: function(data) {
            if (data.status) {
                setTimeout(function(){
                    $('.load').hide();
                    var t = JSON.parse(data.v);
                    $('.search-result lable').eq(0).html(t.count);
                    $.each(t.data, function(k, v) {
                        $('.evaluation-item-demo .evaluation-item').attr('data-evaluation_id',v.id);
                        $('.evaluation-item-demo .evaluation-name').html(v.name);
                        $('.evaluation-item-demo .evaluation-sub-name').html(v.sub_name);
                        $('.evaluation-item-demo .evaluation-img').attr('src',v.img);
                        $('.evaluation-box').append($('.evaluation-item-demo').html());
                    });
                    is_bool=t.have;
                    page_no++;
                    if(!t.have){
                        $('.no-data').show();
                    }
                },1000);
                // lazyLoad();
                // $(window).scroll();
            } else {

            }
        }
    });
}

function toEvaluationContent(obj){
    location.href=getRootPath()+'/GasHome/Evaluation/evaluationContent?park_id='+$('#park_id').val()+'&evaluation_id='+$(obj).attr('data-evaluation_id');
}


function getMonthQuestion(){
    $.ajax({
        type: "post",
        url: "Api/Evaluation/getMonthQuestion",
        data: {
            park_id: $('#park_id').val(),
            admin_id:$('#admin_id').val()
        },
        async: true,
        dataType: 'json',
        success: function(data) {
            if (data.status) {
                var t=JSON.parse(data.v);
                $('.Model2 .use-integral').attr('data-id',t.id);
                $('.SubMit2').click();
            } else {

            }
        }
    });
}

function showQuestion(obj){
    $('.zhezhao').show();
    $('.question-iframe iframe').attr('src',getRootPath()+'/GasHome/Evaluation/monthQuestion?park_id='+$('#park_id').val()+'&month_id='+$(obj).attr('data-id'));
    $('.question-iframe').animate({top:'0px'},500);
    clearInterval(month_question_inter_val);
}

function showAnswer(obj){
    $('.zhezhao').show();
    $('.answer-iframe iframe').attr('src',getRootPath()+'/GasHome/Evaluation/monthAnswer?park_id='+$('#park_id').val()+'&month_id='+$(obj).attr('data-id'));
    $('.answer-iframe').animate({top:'0px'},500);
    clearInterval(month_question_inter_val);
}


function showResult(right_count,get_integral){
    $('.Model1 .right-count').html(right_count);
    $('.Model1 .get-integral').html(get_integral);
    $('.SubMit1').click();
}